from django.shortcuts import get_object_or_404
from core.models import Event

class Strategy:
    common_strategy = 1
    common_without_patron_strategy = 2


def check_patrons(strategy):
    with_patron = {
                   Strategy.common_strategy: True,
                   Strategy.common_without_patron_strategy: False
                   }.get(strategy, False)
    return with_patron


def get_current_sum_for_user(id, strategy, investment, patron):    
    result = {
              Strategy.common_strategy: \
                get_sum_for_common_strategy(id, investment, patron),
              Strategy.common_without_patron_strategy: \
                get_sum_for_common_strategy_without_patron(id, investment)  
              }.get(strategy, 0)
    
    return result


def get_sum_for_common_strategy(id, investment, patron):
    event = get_object_or_404(Event, id=id)
    event_cost = event.cost
    user_count = event.participants.count() 
    current_sum_for_user = event_cost / user_count
    return current_sum_for_user

def get_sum_for_common_strategy_without_patron(id, investment):
    event = get_object_or_404(Event, id=id)
    event_cost = event.cost
    user_count = event.participants.count() 
    current_sum_for_user = event_cost / user_count
    
    return current_sum_for_user